package cn.hloger.spider.utils;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * TODO
 *
 * @author huanglong
 * @Description TODO
 * @data 2022/9/13
 */
public class DateUtils {
    /**
     * 获取两个时间之间的相隔的天数
     *
     * @param endDateTime
     * @return
     */
    public static int getDifferentDayByNow(LocalDateTime endDateTime) {
        LocalDateTime now = LocalDateTime.now();
        Duration duration = Duration.between(now, endDateTime);
        return (int) duration.toDays() + 1;
    }


    public static String getDateNew() {
        return DateFormatUtils.format(new Date(), "yyyy-MM-dd hh:mm:ss");
    }

    public static String getDate() {
        return DateFormatUtils.format(new Date(), "MMdd");
    }

//
//
//    public static void main(String[] args) throws ParseException {
//        LocalDateTime now = LocalDateTime.now();
//        ZoneId zone = ZoneId.systemDefault();
//        Instant instant = now.atZone(zone).toInstant();
//        java.util.Date da = Date.from(instant);
//        System.out.println(DateFormatUtils.format(da, "yyyy-MM-dd hh:mm:ss"));
//
//        LocalDateTime of = LocalDateTime.of(2022, 10, 4, 0, 0, 0);
//        ZoneId zone1 = ZoneId.systemDefault();
//        Instant instant1 = of.atZone(zone1).toInstant();
//        java.util.Date da1 = Date.from(instant1);
//        System.out.println(DateFormatUtils.format(da1, "yyyy-MM-dd HH:mm:ss"));
//
//        Duration duration = Duration.between(now, of);
//        System.out.println(duration.toMillis());
//        System.out.println(duration.toMinutes());
//        System.out.println(duration.toHours());
//        System.out.println(duration.toDays() + 1);
//    }

}
